use shq_common::prelude::{get_my_pool, Role};
use sqlx::{Error, Row};  

pub async fn get_roles_list() -> Result<Vec<Role>, Error> {
    let sql = "select id as roid,name from sys_role";
    // 执行SQL语句，获取查询结果
    let rows = sqlx::query(sql)
        .fetch_all(get_my_pool())
        .await?;
    let mut roles = Vec::new();
    for row in rows.iter() {
        let id: u32 = row.try_get(0)?;
        let name: String = row.try_get(1)?;
        let role = Role { id, name };
        roles.push(role);
    }
    Ok(roles)
}